<template>
  <div>
    <el-form :model="formList" ref="formList" size="normal">
      <el-form-item label="招标项目名称">
        <el-input v-model="formList.project_name"></el-input>
      </el-form-item>
    </el-form>
    <div class="center">
      <el-button type="danger" size="medium" @click="cancel">取消</el-button>
      <template v-if="this.switch">
        <el-button type="primary" size="medium" @click="onAdd" :loading="saveLoading" v-if="!formList.id">新增</el-button>
        <el-button type="primary" size="medium" @click="onEdit" :loading="saveLoading" v-else>修改</el-button>
      </template>
    </div>
  </div>
</template>
<script>
export default {
  name: 'BidProject',
  components: {

  },
  props: {
    switch: {
      type: Boolean,
      default: () => {
        return false
      }
    },
    formList: {
      type: Object,
      default: () => {
        return {}
      }
    },
  },
  data () {
    return {
      saveLoading: false
    }
  },
  created () {

  },
  mounted () {
  },
  methods: {
    async onAdd () {
      this.saveLoading = true
      if (!this.check()) {
        this.saveLoading = false
        return false
      }
      const res = await this.$http('blockProjectAdd', {
        del_flag: '0',
        status: this.formList.status,
        grade: '1',
        project_name: this.formList.project_name,
        source: this.formList.source
      })
      this.$tips.success(res.errmsg)
      this.$emit('cancel')
      this.$emit('init')
      this.saveLoading = false
    },
    async onEdit () {
      this.saveLoading = true
      if (!this.check()) {
        this.saveLoading = false
        return false
      }
      const res = await this.$http('blockProjectUp', {
        del_flag: '0',
        id: this.formList.id,
        project_name: this.formList.project_name
      })
      this.$tips.success(res.errmsg)
      this.$emit('cancel')
      this.$emit('init')
      this.saveLoading = false
    },
    check () {
      if (!this.formList.project_name) {
        this.$tips.error('请填写名称')
        return false
      }
      return true
    },
    cancel () {
      this.$emit('cancel')
    }
  },
  computed: {

  }
}
</script>
<style lang='scss' scoped>
</style>
